<template>
	<view class="bill">
		<view class="form">
			<view class="l_left">
				开票金额
			</view>
			<view class="l_right">
				<input type="digit" v-model="money" placeholder="请输入开票金额" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				开票类型
			</view>
			<label class="labels">
				<view class="l_box" @click="toChecked(1)">
					<radio class="radio" :checked="type==1" color="#FF7416"/><text>普票</text>
				</view>
				<view class="l_box" @click="toChecked(2)">
					<radio class="radio" :checked="type==2" color="#FF7416"/><text>专票</text>
				</view>
				
			</label>
			<view class="l_left">
				开票单位
			</view>
			<view class="l_right">
				<input type="text" v-model="company" placeholder="请输入开票单位" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				统一社会信用代码
			</view>
			<view class="l_right">
				<input type="text" v-model="uniquecode" placeholder="请输入统一社会信用代码" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				地址
			</view>
			<view class="l_right">
				<input type="text" v-model="address" placeholder="请输入地址" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				电话
			</view>
			<view class="l_right">
				<input type="text" v-model="phone" placeholder="请输入电话" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				开户行
			</view>
			<view class="l_right">
				<input type="text" v-model="bankname" placeholder="请输入开户行" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				银行账号
			</view>
			<view class="l_right">
				<input type="text" v-model="bankcard" placeholder="请输入银行账号" placeholder-class="inp" maxlength="-1" />
			</view>
			<view class="l_left">
				备注
			</view>
			<view class="remark">
				<textarea :value="remark" placeholder="请输入备注" placeholder-class="inp" @input="setRemark" maxlength="-1"/>
			</view>
			<view class="" style="height: 20rpx;">
				
			</view>
		</view>
		<view class="hint">
			点击提交即代表您同意<text @click="toNav(1)">《用户服务协议》</text>及<text @click="toNav(2)">《隐私政策》</text>
		</view>
		<button class="btn" type="default" @click="toSubmit">提交</button>
		<view class="" style="height: 100rpx;">
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money:'',
				company:'',
				uniquecode:'',
				address:'',
				phone:'',
				bankname:'',
				bankcard:'',
				remark:'',
				type:1,
				mid:''
			}
		},
		onLoad() {
	
		},
		onShareAppMessage(e) {
			return {
				title: '',
				path: '/pages/index/index'
			}
		},
		methods: {
			//协议
			toNav(e){
				uni.navigateTo({
					url:'agreement?type='+e
				})
			},
			toSubmit(){
				if(uni.getStorageSync('user')){
					if(this.money==''){
						uni.showToast({
							title:'请填写开票金额',
							icon:'none'
						})
						return
					}
					if(this.company==''){
						uni.showToast({
							title:'请填写开票单位',
							icon:'none'
						})
						return
					}
					if(this.company==''){
						uni.showToast({
							title:'请填写开票单位',
							icon:'none'
						})
						return
					}
					if(this.uniquecode==''){
						uni.showToast({
							title:'请填写统一社会信用码',
							icon:'none'
						})
						return
					}
					if(this.address==''){
						uni.showToast({
							title:'请填写地址',
							icon:'none'
						})
						return
					}
					if(this.phone==''){
						uni.showToast({
							title:'请填写电话',
							icon:'none'
						})
						return
					}
					if(this.bankname==''){
						uni.showToast({
							title:'请填写开户行',
							icon:'none'
						})
						return
					}
					if(this.bankcard==''){
						uni.showToast({
							title:'请填写银行账号',
							icon:'none'
						})
						return
					}
					if(this.remark==''){
						uni.showToast({
							title:'请填写备注',
							icon:'none'
						})
						return
					}
					uni.showLoading({
						mask:true
					})
					this.mid = uni.getStorageSync('user').id
					this.$post('user/invoiceSubmit',{
						address:this.address,
						bankcard:this.bankcard,
						bankname:this.bankname,
						company:this.company,
						mid:this.mid,
						money:this.money,
						phone:this.phone,
						remark:this.remark,
						type:this.type,
						uniquecode:this.uniquecode
					}).then(res=>{
						uni.hideLoading()
						// console.log(res)
						if(res.code==0){
							uni.showToast({
								title:res.msg,
								mask:true
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1000)
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none',
								mask:true
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1000)
						}
						
					})
				}else{
					uni.showToast({
						title:'暂未登录',
						icon:'none'
					})
				}
			},
			setRemark(e){
				// // console.log(e.detail.value)
				this.remark = e.detail.value
			},
			toChecked(e){
				if(e==1){
					this.type = 1
				}else{
					this.type = 2
				}
			}
		}
	}
</script>

<style lang="less">
	.bill{
		padding-top: 20rpx;
		.hint{
			font-size: 24rpx;
			text-align: center;
			margin-top: 30rpx;
			text{
				color: #FF7416;
			}
		}
		.btn{
			width: 80%;
			background-color: #FF7416;
			color: #333333;
			margin: 0 auto;
			margin-top: 50rpx;
			color: #fff;
		}
		.form{
			width: 700rpx;
			margin: 0 auto;
			border-radius: 20rpx;
			box-shadow: 0rpx 10rpx 20rpx #eaeae8;
			padding: 0 20rpx;
			padding-top: 20rpx;
			box-sizing: border-box;
			font-size: 30rpx;
			.labels{
				font-size: 30rpx;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				.l_box{
					display: flex;
					align-items: center;
					.radio{
						transform:scale(0.7)
					}
				}
				
			}
			.l_left{
				padding-bottom: 20rpx;
				font-weight: 600;
			}
			.l_right{
				// text-align: right;
				height: 50rpx;
				padding-bottom: 20rpx;
				input{
					height: 100%;
				}
			}
			.remark{
				height: 150rpx;
				textarea{
					width: 100%;
					height: 100%;
				}
			}
			.inp{
				font-size: 30rpx;
			}
		}
	}
	
</style>
